--Script stuff to make the boss hittable again.

addHook("MobjSpawn", function(mobj)
	if not mapheaderinfo[gamemap].hydroaltarlua then return end
	mobj.damagecounter = -1
end,MT_HYDROBATTLE_BOSS)

addHook("MobjThinker", function(mobj)
	if not mapheaderinfo[gamemap].hydroaltarlua then return end
	--Clearing MF2_FRET flag
	if (mobj.damagecounter > 0)
		mobj.damagecounter = mobj.damagecounter - 1
	end
	if (mobj.damagecounter == 0 and mobj.flags2 & MF2_FRET)
		mobj.flags2 = mobj.flags2 - MF2_FRET
		mobj.damagecounter = -1
	end
	--Adjusting state properties
	if (mobj.tics >= 50)
		if (mobj.health <= 3)
			mobj.tics = mobj.health + 3
		elseif (mobj.health <= 8)
			mobj.tics = mobj.health / 2 + 5
		else
			mobj.tics = mobj.health / 3 + 7
		end
	end
end,MT_HYDROBATTLE_BOSS)

addHook("MobjDamage", function(mobj)
	if not mapheaderinfo[gamemap].hydroaltarlua then return end
	mobj.damagecounter = 128
end,MT_HYDROBATTLE_BOSS)

addHook("BossDeath", function(mobj)
	if not mapheaderinfo[gamemap].hydroaltarlua then return end
	for player in players.iterate
		if not (player.pflags & PF_FINISHED)
			player.pflags = $ + PF_FINISHED
		end
	end
end)